package dao.impl;

import dao.IProvinceTopProductDAO;
import domain.ProvinceTopProduct;
import jdbc.JDBCHelper;

import java.util.ArrayList;
import java.util.List;

public class ProvinceTopProductDAO implements IProvinceTopProductDAO {
    @Override
    public void insertBatch(List<ProvinceTopProduct> provinceTopProductList) {
        String sql = "insert into province_top_product values(?,?,?,?,?)";
        ArrayList<Object[]> paramsList = new ArrayList<>();

        for (ProvinceTopProduct provinceTopProduct : provinceTopProductList) {
            Object[] params = new Object[5];
            params[0] = provinceTopProduct.getTaskId();
            params[1] = provinceTopProduct.getProvince();
            params[2] = provinceTopProduct.getProductid();
            params[3] = provinceTopProduct.getClickCount();
            params[4]= provinceTopProduct.getCityInfos();
            paramsList.add(params);
        }
        JDBCHelper jdbcHelper = JDBCHelper.getInstance();
        jdbcHelper.executeBatch(sql, paramsList);

    }
}
